//
//  AirConditionerView.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/5.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "AirConditionerView.h"

@implementation AirConditionerView

- (void)didClickButton:(UIButton *)sender
{
    NSLog(@"click---%@",sender.titleLabel.text);
    if ([self.delegate respondsToSelector:@selector(airConditionerViewnSelectedIndex:)])
    {
        [self.delegate airConditionerViewnSelectedIndex:sender.tag];
    }
}

- (UIImageView *)headView
{
    if(!_headView)
    {
        UIView *superView = self;
        _headView = [[UIImageView alloc]init];
        [superView addSubview:_headView];
        _headView.image = [UIImage imageNamed:@"AirCondition_head"];
    }
    return _headView;
}

- (UILabel *)tempLabel
{
    if(!_tempLabel)
    {
        UIView *superView = self;
        _tempLabel = [[UILabel alloc]init];
        [superView addSubview:_tempLabel];
//        [_tempLabel setFont:fontWithSize(16)];
        _tempLabel.textAlignment = NSTextAlignmentCenter;
        _tempLabel.text = @"24℃";
        [_tempLabel setTextColor:[UIColor whiteColor]];
    }
    return _tempLabel;
}


- (void)masLayoutSubview
{
    __weak UIView *superView = self;

    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top);
        make.left.right.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(748));
    }];
    
    
//    UIView *bgView = [[UIView alloc] init];
//    [superView addSubview:bgView];
//    bgView.backgroundColor = rgba(65,98,170,1);
//    bgView.layer.cornerRadius = 3;
//    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.headView.mas_bottom).with.offset(px1920Height(100));
//        make.right.mas_equalTo(superView.mas_right).with.offset(-px1080Width(90));
//        make.width.mas_equalTo(px1080Width(240));
//        make.height.mas_equalTo(px1920Height(479));
//    }];
    
    NSArray *array = @[@[@"",@"-",@"+"],
                       @[@"风速",@"上下扫风",@"左右扫风"],
                       @[@"健康/节能",@"超强",@"干燥·辅热"]];
//                       @[@"干燥·辅热",@"温度显示",@"定时"],
//                       @[@"超强",@"睡眠",@"灯光"]];
    
    UIView *lastView;
    [superView addSubview:lastView];
    for (int i = 0; i < 3; i++)      // 行
    {
        for (int j = 0; j < 3; j++)    // 列
        {

            UIButton *button = [[UIButton alloc] init];
            [superView addSubview:button];
            [button setBackgroundColor:rgba(65,98,170,1)];
            [button setTitle:array[i][j] forState:UIControlStateNormal];
            [button.titleLabel setFont:fontCommonSize];
            if (i == 0 && (j == 1 || j == 2))
            {
                [button.titleLabel setFont:fontWithSize(30)];
            }
            if (i == 0)
            {
                if (j == 0)
                {
                    [button setImage:imageWithName(@"icon_power") forState:UIControlStateNormal];
                    [button setBackgroundColor:rgba(251,74,79,1)];
                }
//                else if (j == 1)
//                {
//                    [button setImage:imageWithName(@"icon_mute") forState:UIControlStateNormal];
//                }
            }
            button.layer.cornerRadius = 3;
            button.tag = (i+1)*10+j+1;
            [button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                if (i == 0)
                {
                    make.top.mas_equalTo(self.headView.mas_bottom).with.offset(px1920Height(100));
                }
                else if (j == 0)
                {
                    make.top.mas_equalTo(lastView.mas_bottom).with.offset(px1920Height(70));
                }
                else
                {
                    make.top.mas_equalTo(lastView);
                }
                
                if (j == 0)
                {
                    make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(90));
                }
                else
                {
                    make.left.mas_equalTo(lastView.mas_right).with.offset(px1080Width(90));
                }
                
                make.height.mas_equalTo(px1920Height(113));
                make.width.mas_equalTo(px1080Width(240));
                
            }];
            
            
//            if (i == 1 && j == 2)
//            {
//                button.userInteractionEnabled = NO;
//                [self.tempLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
//                    make.edges.mas_equalTo(button);
//                }];
//            }
            lastView = button;
        }
    }

}

@end
